package com.jy.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.Arrays;

@RestController
@RequestMapping("/consumer/")
public class RestConsumerController {
    @Autowired
    private RestTemplate loadBalancedRestTemplate;
    @DeleteMapping("{id}")
    public String doDeleteById(@PathVariable Long... id){
        System.out.println("id1="+id);
        System.out.println("id2="+Arrays.toString(id));//[1,2,3]
        String idArray=Arrays.toString(id);
        idArray=idArray.substring(1,idArray.length()-1);
        System.out.println("idArray="+idArray);
        String url=String.format("http://%s/provider/%s","sca-provider",id);
        loadBalancedRestTemplate.delete(url);
        return "delete ok";
    }
}
